home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / asmexam.arc / ASCIIBIN.LST < prev    next >
File List  |  1984-07-10  |  7KB  |  207 lines

  1.  The Microsoft MACRO Assembler             07-10-84        PAGE    1-1
  2. 'ASCBIN - ASCII to binary conversion'
  3.  
  4.  
  5.                     name   ascbin
  6.                     page   55,132
  7.                     title  'ASCBIN - ASCII to binary conversion'
  8.                     comment *
  9.                     
  10.                       This program contains a pair of routines to convert
  11.                       either decimal or hexidecimal ascii strings
  12.                       to 32 bit binary integers
  13.                       The main prog should load si with the address of the string
  14.                       the proc leaves the 32 bit result in DX,CX
  15.                     
  16.                             *
  17.  0000                   cseg   segment para
  18.                            assume  cs:cseg,ds:cseg,ss:cseg
  19.                     
  20.  0000  31 32 33 7A 7A 7A    decnum: db '123','zzzz' ; z's are for extra locations
  21.        7A              
  22.  0007  31 61 65 7A 7A 7A    hexnum: db '1ae','zzzz'
  23.        7A              
  24.  0100                          org 100h
  25.  0100                   main   proc near
  26.  0100  8C C8                     mov ax,cs
  27.  0102  8E D8                     mov ds,ax  ; these two statements set up ds reg for debug
  28.  0104  8D 36 0000 R                lea si,decnum
  29.  0108  E8 0114 R                call decbin
  30.                     
  31.  010B  8D 36 0007 R                lea si,hexnum
  32.  010F  E8 017D R                call hexbin
  33.                     
  34.  0112  CD 20                     int 20h
  35.                     
  36.                     
  37.  0114                   main   endp
  38.                     
  39.                     
  40.  0114                   decbin proc near
  41.  0114  33 C9                     xor     cx,cx
  42.  0116  33 D2                     xor     dx,dx
  43.  0118  BB FFFF                     mov     bx,-1
  44.  011B  8A 04                     mov     al,[si]
  45.  011D  3C 2B                     cmp     al,'+'
  46.  011F  75 04                     jne     decbin1
  47.  0121  46                     inc     si
  48.  0122  EB 08 90                     jmp     decbin2
  49.                     
  50.  0125                   decbin1:
  51.  0125  3C 2D                     cmp     al,'-'
  52.  0127  75 03                     jne     decbin2
  53.  0129  32 FF                     xor     bh,bh
  54.  012B  46                     inc     si
  55.  The Microsoft MACRO Assembler             07-10-84        PAGE    1-2
  56. 'ASCBIN - ASCII to binary conversion'
  57.  
  58.  
  59.                     
  60.  012C                   decbin2:
  61.  012C  AC                     lodsb
  62.  012D  0A C0                     or      al,al
  63.  012F  74 3C                     jz      decbin8
  64.  0131  3C 2E                     cmp     al,'.'
  65.  0133  74 2E                     jz      decbin4
  66.  0135  3C 39                     cmp     al,'9'
  67.  0137  77 32                     ja      decbin7
  68.  0139  3C 30                     cmp     al,'0'
  69.  013B  72 2E                     jb      decbin7
  70.  013D  0A DB                     or      bl,bl
  71.  013F  78 02                     js      decbin3
  72.  0141  FE C3                     inc     bl
  73.                     
  74.  0143                   decbin3:
  75.  0143  50                     push    ax
  76.  0144  8B F9                     mov     di,cx
  77.  0146  8B C2                     mov     ax,dx
  78.  0148  D1 E1                     shl     cx,1
  79.  014A  D1 D2                     rcl     dx,1
  80.  014C  D1 E1                     shl     cx,1
  81.  014E  D1 D2                     rcl     dx,1
  82.  0150  03 CF                     add     cx,di
  83.  0152  13 D0                     adc     dx,ax
  84.  0154  D1 E1                     shl     cx,1
  85.  0156  D1 D2                     rcl     dx,1
  86.  0158  58                     pop     ax
  87.  0159  25 000F                     and     ax,0fh
  88.  015C  03 C8                     add     cx,ax
  89.  015E  83 D2 00                     adc     dx,0
  90.  0161  EB C9                     jmp     decbin2
  91.                     
  92.  0163                   decbin4:
  93.  0163  0A DB                     or      bl,bl
  94.  0165  79 04                     jns     decbin7
  95.  0167  32 DB                     xor     bl,bl
  96.  0169  EB C1                     jmp     decbin2
  97.                     
  98.  016B                   decbin7:
  99.  016B  F9                     stc
  100.  016C  C3                     ret
  101.                     
  102.  016D                   decbin8:
  103.  016D  0A FF                     or      bh,bh
  104.  016F  75 0A                     jnz     decbin9
  105.  0171  F7 D1                     not     cx
  106.  0173  F7 D2                     not     dx
  107.  0175  83 C1 01                     add     cx,1
  108.  0178  83 D2 00                     adc     dx,0
  109.  The Microsoft MACRO Assembler             07-10-84        PAGE    1-3
  110. 'ASCBIN - ASCII to binary conversion'
  111.  
  112.  
  113.                     
  114.  017B                   decbin9:
  115.  017B  F8                     clc
  116.  017C  C3                     ret
  117.  017D                   decbin endp
  118.                     
  119.                     
  120.  017D                   hexbin proc    near
  121.  017D  33 C9                     xor     cx,cx
  122.  017F  33 D2                     xor     dx,dx
  123.                     
  124.  0181                   hexbin1:
  125.  0181  AC                     lodsb
  126.  0182  0A C0                     or      al,al
  127.  0184  74 2D                     jz      hexbin8
  128.  0186  3C 30                     cmp     al,'0'
  129.  0188  72 27                     jb      hexbin7
  130.  018A  3C 39                     cmp     al,'9'
  131.  018C  76 0C                     jbe     hexbin3
  132.                     
  133.  018E                   hexbin2:
  134.  018E  0C 20                     or      al,20h
  135.  0190  3C 66                     cmp     al,'f'
  136.  0192  77 1D                     ja      hexbin7
  137.  0194  3C 61                     cmp     al,'a'
  138.  0196  72 19                     jb      hexbin7
  139.  0198  04 09                     add     al,9
  140.                     
  141.  019A                   hexbin3:
  142.  019A  D1 E1                     shl     cx,1
  143.  019C  D1 D2                     rcl     dx,1
  144.  019E  D1 E1                     shl     cx,1
  145.  01A0  D1 D2                     rcl     dx,1
  146.  01A2  D1 E1                     shl     cx,1
  147.  01A4  D1 D2                     rcl     dx,1
  148.  01A6  D1 E1                     shl     cx,1
  149.  01A8  D1 D2                     rcl     dx,1
  150.  01AA  25 000F                     and     ax,0fh
  151.  01AD  0B C8                     or      cx,ax
  152.  01AF  EB D0                     jmp     hexbin1
  153.                     
  154.  01B1                   hexbin7:
  155.  01B1  F9                     stc
  156.  01B2  C3                     ret
  157.                     
  158.  01B3                   hexbin8:
  159.  01B3  F8                     clc
  160.  01B4  C3                     ret
  161.                     
  162.  01B5                   hexbin endp
  163.  The Microsoft MACRO Assembler             07-10-84        PAGE    1-4
  164. 'ASCBIN - ASCII to binary conversion'
  165.  
  166.  
  167.                     
  168.  01B5                   cseg   ends
  169.                     
  170.                            end  main
  171.  
  172.  The Microsoft MACRO Assembler             07-10-84        PAGE    Symbols-1
  173. 'ASCBIN - ASCII to binary conversion'
  174.  
  175.  
  176. Segments and groups:
  177.  
  178.          N a m e              Size    align    combine    class
  179.  
  180. CSEG . . . . . . . . . . . . . .    01B5    PARA      NONE    
  181.  
  182. Symbols:            
  183.  
  184.          N a m e              Type    Value    Attr         
  185.  
  186. DECBIN . . . . . . . . . . . . .    N PROC    0114    CSEG    Length =0069
  187. DECBIN1. . . . . . . . . . . . .    L NEAR     0125    CSEG
  188. DECBIN2. . . . . . . . . . . . .    L NEAR     012C    CSEG
  189. DECBIN3. . . . . . . . . . . . .    L NEAR     0143    CSEG
  190. DECBIN4. . . . . . . . . . . . .    L NEAR     0163    CSEG
  191. DECBIN7. . . . . . . . . . . . .    L NEAR     016B    CSEG
  192. DECBIN8. . . . . . . . . . . . .    L NEAR     016D    CSEG
  193. DECBIN9. . . . . . . . . . . . .    L NEAR     017B    CSEG
  194. DECNUM . . . . . . . . . . . . .    L NEAR     0000    CSEG
  195. HEXBIN . . . . . . . . . . . . .    N PROC    017D    CSEG    Length =0038
  196. HEXBIN1. . . . . . . . . . . . .    L NEAR     0181    CSEG
  197. HEXBIN2. . . . . . . . . . . . .    L NEAR     018E    CSEG
  198. HEXBIN3. . . . . . . . . . . . .    L NEAR     019A    CSEG
  199. HEXBIN7. . . . . . . . . . . . .    L NEAR     01B1    CSEG
  200. HEXBIN8. . . . . . . . . . . . .    L NEAR     01B3    CSEG
  201. HEXNUM . . . . . . . . . . . . .    L NEAR     0007    CSEG
  202. MAIN . . . . . . . . . . . . . .    N PROC    0100    CSEG    Length =0014
  203.  
  204. Warning Severe
  205. Errors    Errors 
  206. 0    0
  207.